const merge = require("webpack-merge")
const path = require("path")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const OpenBrowserPlugin = require("open-browser-webpack-plugin")
const baseDev = require("../base/dev")

const host = "localhost"
const port = 3000

module.exports = function(env) {
  process.env.mode = "development"
  let devConfig = {
    entry: "./web/index.web.tsx",
    output: {
      path: path.join(__dirname, "dist"),
      filename: "bundle.js",
      library: "app-lightapp-front",
      libraryTarget: "umd"
    },
    devServer: {
      port
    },
    module: {
      rules: [
        {
          test: /\.js[x]?$/,
          exclude: /node_modules/,
          use: [
            {
              loader: "babel-loader"
            }
          ]
        }
      ]
    },
    // 不要遵循/打包这些模块，而是在运行时从环境中请求他们
    plugins: [
      new HtmlWebpackPlugin({
        filename: "index.html",
        template: "./web/index.html",
        inject: "body"
      }),
      new OpenBrowserPlugin({ url: `http://${host}:${port}` }) // 构建完成打开浏览器插件
    ]
  }

  devConfig = merge(baseDev(env), devConfig)
  return devConfig
}
